﻿/**
 * ...
 * @author alijaya
 */
package homponex.utils;
import flash.display.Sprite;

class Grid extends Sprite
{

	var w:Float;
	var h:Float;
	var p:Array<Profile>;
	
	public function new(w_:Float, h_:Float, p_:Array<Profile>) 
	{
		super();
		w = w_;
		h = h_;
		p = p_;
		for (n in p)
		{
			createGrid(n);
		}
	}
	
	private function createGrid(n:Profile)
	{
		graphics.lineStyle(n.t, n.c);
		var nX:Int = Std.int(w / n.sX) + 1;
		var nY:Int = Std.int(h / n.sY) + 1;
		for (j in 0...nY)
		{
			var row:Float = j * n.sY;
			graphics.moveTo(0, row);
			graphics.lineTo(w, row);
		}
		for (i in 0...nX)
		{
			var col:Float = i * n.sX;
			graphics.moveTo(col, 0);
			graphics.lineTo(col, h);
		}
	}
	
}
typedef Profile = { sX:Float, sY:Float, t:Float, c:UInt }